package com.md.mainpage.adapter;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.living.player.PlayUtils;
import com.md.basedpc.PHHighLightWordsUtils;
import com.md.mainpage.R;
import com.md.network.api.Audio;
import com.md.network.api.SearchedAudio;

import org.jetbrains.annotations.NotNull;

public class SearchAdapter2 extends BaseQuickAdapter<SearchedAudio, BaseViewHolder> {

    String keywords = "";
    boolean isShowAdd = false;

    public void setShowAdd(boolean showAdd) {
        isShowAdd = showAdd;
        notifyDataSetChanged();
    }

    public void setKeywords(String keywords) {
        this.keywords = keywords;
    }

    public SearchAdapter2() {
        super(R.layout.adapter_search);
        addChildClickViewIds(R.id.cltSearchResult);
        addChildClickViewIds(R.id.iv_search_addabulm);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder baseViewHolder, SearchedAudio audio) {
        String albumName= null;
        //TODO 如果一个音频存在于多个专辑中，搜索结果该展示哪个？
        if (audio.getAlbums() !=null && audio.getAlbums().size()>0){
            albumName = audio.getAlbums().get(0).getName();
        }
        baseViewHolder.setText(R.id.tvTitle, PHHighLightWordsUtils.getHighLightWord(audio.getName() + "", keywords, getContext().getResources().getColor(R.color.maincolor_12C286)));
        baseViewHolder.setText(R.id.tvTitleDes, audio.getAuthor() + "《" + albumName + "》");
        if (isShowAdd) {
            if (audio.isAddAlbum()) {
                baseViewHolder.setGone(R.id.tv_search_added, false);
                baseViewHolder.setGone(R.id.iv_search_addabulm, true);
                baseViewHolder.setText(R.id.tv_search_added, "已添加");
            } else {
                baseViewHolder.setGone(R.id.tv_search_added, true);
                baseViewHolder.setGone(R.id.iv_search_addabulm, false);
            }
        } else {
            baseViewHolder.setGone(R.id.tv_search_added, true);
            baseViewHolder.setGone(R.id.iv_search_addabulm, true);
        }

    }
}
